<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>角色设置菜单栏</title>
		<link rel="stylesheet" href="layui/css/layui.css" media="all">
		<link rel="stylesheet" href="css/public.css" media="all">
		<style>
			body {
				background-color: #ffffff;
			}
		</style>
	</head>
	<body>
		<form class="layui-form" id="forms">
			<div class="layui-form-item" hidden="hidden">
				<label class="layui-form-label">角色ID:</label>
				<div class="layui-input-inline" style="width: 350px;">
					<input type="text" id="roleid" name="roleid" required lay-verify="required" class="layui-input">
				</div>
			</div>
		</form>
		<div id="role_transfer" class="demo-transfer"></div>
		<script type="text/javascript" src="layui/layui.js"></script>
	<script src="js/Global.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
		layui.use(['transfer','form'], function() {
			var transfer = layui.transfer,$=layui.$;
			setTimeout( function(){
				var rdata=new Array();
			     //add your code
			    $.post(globalData.server+"public/getAllBoxRoleMenus",{
					"roleid":document.getElementById("roleid").value
				},function(result){
					if(result.count>0){
						for(var i=0;i<result.data.length;i++){
							rdata.push(result.data[i].menuid)
						}
					}
					},"json");
					console.log(rdata);
				setTimeout( function(){
			 	$.post(globalData.server+"public/getAllBoxMenus",
						{
							"roleid":document.getElementById("roleid").value
						},function(data){
							console.log(data)
						transfer.render({
							elem : '#role_transfer',
							data : data.data,
							title:['系统所有菜单','角色现有菜单'],
							parseData:function(res){
								return{
									"value":res.menuid,
									"title":res.menuname
								}
							},
							value: rdata,
							id : 'role_transfer_id' ,
							onchange:function(obj,index){
								if(index=="0"){
									for(var i=0;i<obj.length;i++){
										$.post(globalData.server+"public/addBoxMenus",{
											"roleid":document.getElementById("roleid").value,
											"menuid":obj[i].value
										},function(result){
										},"json");
									}
								} else {
									for(var i=0;i<obj.length;i++){
										$.post(globalData.server+"public/deleteBoxMenus",{
											"roleid":document.getElementById("roleid").value,
											"menuid":obj[i].value
										},function(result){
										},"json");
									}
								}
							}
						});
						},"json"); 
						}, 150 );
			}, 100 );
			
		});
	</script>
	</body>

</html>